﻿Public Class frmMain
    Dim CW As Integer = Me.Width ' Current Width
    Dim CH As Integer = Me.Height ' Current Height
    Dim IW As Integer = Me.Width ' Initial Width
    Dim IH As Integer = Me.Height ' Initial Height
    Dim networkavailablity As Boolean
    Dim newinstance As Boolean = True
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        IW = Me.Width
        IH = Me.Height
        Dim defaulttab As New deftab
        defaulttab.TopLevel = False
        tabtemplate.Controls.Add(defaulttab)
        defaulttab.Dock = DockStyle.Fill
        defaulttab.Show()
        Dim returnValue As String()
        returnValue = Environment.GetCommandLineArgs()
        If returnValue.Length > 1 Then
            CType(Me.tabs.TabPages(Me.tabs.SelectedIndex).Controls(0).Controls(0), Awesomium.Windows.Forms.WebControl).Source = New Uri((returnValue(1).ToString()))
        End If
last:
    End Sub
    Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
        Dim RW As Double = (Me.Width - CW) / CW ' Ratio change of width
        Dim RH As Double = (Me.Height - CH) / CH ' Ratio change of height

        For Each Ctrl As Control In Controls
            Ctrl.Width += CInt(Ctrl.Width * RW)
            Ctrl.Height += CInt(Ctrl.Height * RH)
            Ctrl.Left += CInt(Ctrl.Left * RW)
            Ctrl.Top += CInt(Ctrl.Top * RH)
        Next
        CW = Me.Width
        CH = Me.Height
    End Sub
    Private Sub tabs_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles tabs.MouseDoubleClick
        tabs.TabPages.RemoveAt(tabs.SelectedIndex)
    End Sub
    Private Sub tabs_SelectedIndexChanged(sender As Object, e As EventArgs) Handles tabs.SelectedIndexChanged
        If tabs.TabPages.Count = 0 Then
            addtab(newtabrequest:=False, rightclickrequest:=False)
        End If
        Me.Text = tabs.SelectedTab.Text + " - Surfer Vio Express"
        If tabs.SelectedIndex = tabs.TabCount - 1 Then
            Dim newtabrequest As Boolean = True
            addtab(newtabrequest, False)
        End If
    End Sub
    Private Sub networkchecker_Tick(sender As Object, e As EventArgs) Handles networkchecker.Tick
        If My.Computer.Network.IsAvailable <> networkavailablity Then
            If My.Computer.Network.IsAvailable = False Then
                desktop.ContentText = "Network is not connected. Please ensure you are connected to the internet."
                desktop.CaptionText = "Alert - Surfer Vio Express"
                desktop.ContentImage = My.Resources.Warning
                desktop.FixedSize = My.Settings.popupsize
                desktop.Show()
            Else
                desktop.ContentText = "Network is now connected. You may continue browsing."
                desktop.CaptionText = "Alert - Surfer Vio Express"
                desktop.ContentImage = My.Resources.connected
                desktop.FixedSize = My.Settings.popupsize
                desktop.Show()
            End If
        End If
        networkavailablity = My.Computer.Network.IsAvailable
    End Sub
    Public Function addtab(newtabrequest As Boolean, rightclickrequest As Boolean)
        Dim newtab As New TabPage
        Dim defaulttab As New deftab
        If rightclickrequest = False Then
            newtab.Text = "Blank tab"
        Else
            newtab.Text = "Loading..."
        End If
        defaulttab.TopLevel = False
        defaulttab.Parent = newtab
        newtab.Controls.Add(defaulttab)
        defaulttab.Dock = DockStyle.Fill
        newtab.ImageIndex = 1
        If newtabrequest = False Then
            tabs.TabPages.Add(newtab)
        Else
            tabs.TabPages.Insert(tabs.TabPages.Count - 1, newtab)
        End If
        defaulttab.Show()
        tabs.SelectTab(tabs.TabPages.Count - 2)
        Return 0
    End Function

End Class
